define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods_sku_value/index' + location.search,
                    add_url: 'goods_sku_value/add',
                    edit_url: 'goods_sku_value/edit',
                    del_url: 'goods_sku_value/del',
                    multi_url: 'goods_sku_value/multi',
                    import_url: 'goods_sku_value/import',
                    table: 'goods_sku_value',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'sku_id', title: __('Sku_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goods.id', title: __('Goods.id')},
                        {field: 'goods.goods_cate_id', title: __('Goods.goods_cate_id')},
                        {field: 'goods.title', title: __('Goods.title'), operate: 'LIKE'},
                        {field: 'goods.subtitle', title: __('Goods.subtitle'), operate: 'LIKE'},
                        {field: 'goods.score', title: __('Goods.score'), operate: 'LIKE'},
                        {field: 'goods.old_score', title: __('Goods.old_score'), operate: 'LIKE'},
                        {field: 'goods.cost_price', title: __('Goods.cost_price'), operate:'BETWEEN'},
                        {field: 'goods.promise', title: __('Goods.promise'), operate: 'LIKE'},
                        {field: 'goods.address', title: __('Goods.address'), operate: 'LIKE'},
                        {field: 'goods.sku', title: __('Goods.sku'), operate: 'LIKE'},
                        {field: 'goods.sell', title: __('Goods.sell')},
                        {field: 'goods.stock', title: __('Goods.stock')},
                        {field: 'goods.out_time', title: __('Goods.out_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goods.type', title: __('Goods.type')},
                        {field: 'goods.status', title: __('Goods.status'), formatter: Table.api.formatter.status},
                        {field: 'goods.factory', title: __('Goods.factory'), operate: 'LIKE'},
                        {field: 'goods.service', title: __('Goods.service'), operate: 'LIKE'},
                        {field: 'goods.price', title: __('Goods.price'), operate:'BETWEEN'},
                        {field: 'goods.postage', title: __('Goods.postage'), operate:'BETWEEN'},
                        {field: 'goods.is_postage', title: __('Goods.is_postage')},
                        {field: 'goods.is_top', title: __('Goods.is_top')},
                        {field: 'goods.weigh', title: __('Goods.weigh')},
                        {field: 'goods.beizhu', title: __('Goods.beizhu'), operate: 'LIKE'},
                        {field: 'goods.procurement', title: __('Goods.procurement')},
                        {field: 'goods.createtime', title: __('Goods.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goods.updatetime', title: __('Goods.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goodssku.id', title: __('Goodssku.id')},
                        {field: 'goodssku.name', title: __('Goodssku.name'), operate: 'LIKE'},
                        {field: 'goodssku.weigh', title: __('Goodssku.weigh')},
                        {field: 'goodssku.createtime', title: __('Goodssku.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goodssku.updatetime', title: __('Goodssku.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});